import inspect
import logging.config

from flask import Flask, Blueprint

from ._plugins import plugin_init
from ._config import CONFIGS, LOGGER_DICT
import application

__all__ = ('make_app', )


def make_app(name: str = __name__, env: str = 'dev'):

    # Set logger
    logging.config.dictConfig(LOGGER_DICT)

    app = Flask(name)

    # Registered plugins
    plugin_init(app)

    # Registered blueprints
    blueprints = (item[1] for item in inspect.getmembers(application) if isinstance(item[1], Blueprint))
    for blueprint in blueprints:
        app.register_blueprint(blueprint)

    app.config.from_object(CONFIGS[env])

    return app

